package cn.spikego.advicelite.client.core.command.impl

import cn.spikego.advicelite.client.AdviceLite
import cn.spikego.advicelite.client.core.command.Command

class HelpCommand : Command("help", "", "Shows list of commands and their usage") {

    @Throws(Exception::class)
    override fun execute(args: Array<String>) {
        val cmdManager = AdviceLite.getInstance().getCommandManager()
        val spacing = " ".repeat(4)
        AdviceLite.getMinecraftUtil()?.sendSystemMessage("&aAvailable commands&7:")
        cmdManager.getCommandList().forEach { cmd ->
            try {
                AdviceLite.getMinecraftUtil()?.sendSystemMessage(
                    "$spacing&a,${cmd.getPrefix()} &7${cmd.getUsage()} &8- &7${cmd.getDescription()}"
                )
            } catch (_: Exception) {}
        }
    }
}